package com.team.ai.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.team.ai.entity.Question;
import com.team.ai.entity.ResultEntity;
import com.team.ai.service.QuestionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/questions/")
public class QuestionController {
    @Resource
    QuestionService questionService;
    @GetMapping("getQusetions")
    public String getAllQuestions() {
        return  ResultEntity.success(questionService.getAllQuestions());
    }
    @SaCheckLogin
    @PostMapping("uploadScore")
    public String uploadScore(
            @RequestParam(value = "score", defaultValue = "0") int score) {
        int userId = StpUtil.getLoginIdAsInt();
        return questionService.uploadScore(userId,score);
    }

    @SaCheckLogin
    @PostMapping("updateScore")
    public String updateScore(
            @RequestParam(value = "purchaseScore", defaultValue = "0") int purchaseScore) {
        int userId = StpUtil.getLoginIdAsInt();
        return questionService.updateScore(userId,purchaseScore);
    }
    @SaCheckLogin
    @GetMapping("selectById")
    public String selectById() {
        int userId = StpUtil.getLoginIdAsInt();
        return questionService.selectById(userId);
    }

}
